import { Injectable } from '@angular/core'
import { ObservableStore } from '@shared/classes/ObservableStoreClass'
import { deepCopy } from '@delon/util'
import { User } from '@shared/interfaces/user'

@Injectable()
export class UserStoreService extends ObservableStore<User> {
  constructor() {
    super(new User())
  }

  updateValue(users: User): void {
    /* 将传入的 group 和旧的 group 进行合并,注意多级嵌套 */
    const value = deepCopy(this.value)
    Object.assign(value, users)
    this.setValue(value)
  }

  reset(): void {
    this.setValue(new User())
  }
}
